package edu.zjut.hjg.saas.biz.dao.impl;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import edu.zjut.hjg.saas.biz.dao.ResourceDao;
import edu.zjut.hjg.saas.biz.model.Resource;

/**
 * ResourceDao的ibatis实现
 *
 * @author hjg
 */
@SuppressWarnings("unchecked")
public class ResourceDaoImpl extends SqlMapClientDaoSupport implements ResourceDao {

    @Override
    public Resource findByResourceKeyAndRealValue(String resourceKey, String realValue) {
        Resource resource = new Resource();
        resource.setResourceKey(resourceKey);
        resource.setRealValue(realValue);
        return (Resource) getSqlMapClientTemplate().queryForObject(
                "resource.findByResourceKeyAndRealValue", resource);
    }

    @Override
    public List<Resource> listByResourceKey(String resourceKey) {
        return (List<Resource>) getSqlMapClientTemplate().queryForList(
                "resource.listByResourceKey", resourceKey);
    }

    @Override
    public List<Resource> listChildrenByParentId(int parentId) {
        return (List<Resource>) getSqlMapClientTemplate().queryForList(
                "resource.listChildrenByParentId", parentId);
    }

    @Override
    public List<Resource> listChildrenByParentResourceKeyAndRealValue(String resourceKey,
                                                                      String realValue) {
        Resource resource = new Resource();
        resource.setResourceKey(resourceKey);
        resource.setRealValue(realValue);
        return (List<Resource>) getSqlMapClientTemplate().queryForList(
                "resource.listChildrenByParentResourceKeyAndRealValue", resource);
    }

    @Override
    public Resource load(Integer id) {
        return (Resource) getSqlMapClientTemplate().queryForObject("resource.load", id);
    }
}
